package com.example.pages;

import org.openqa.selenium.WebElement;
import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import org.openqa.selenium.support.FindBy;
//import com.example.tests.UsersPage;

public class InternalPage extends AnyPage {
	//@FindBy(xpath = "//div[@id='wrapper']/header//nav//li[1]/a") 
	@FindBy(css = "div[id='wrapper']>header nav a[href$='php4dvd/']")
	public WebElement menuHomeLink;
		
	//@FindBy(xpath = "//div[@id='wrapper']/header//nav//li[2]/a")
	@FindBy(css = "div[id='wrapper']>header nav a[href$='php4dvd/?go=profile']")
	public WebElement menuMyProfileLink;

	//@FindBy(xpath = "//div[@id='wrapper']/header//nav//li[3]/a")
	@FindBy(css = "div[id='wrapper']>header nav a[href$='php4dvd/?go=users']")
	public WebElement menuUserManagementLink;
	
	//@FindBy(xpath = "//div[@id='wrapper']/header//nav//li[4]/a")
	@FindBy(css = "div[id='wrapper']>header nav a[href$='php4dvd/?logout']")
	public WebElement menuLogoutLink;

	@FindBy(linkText = "User management")
	  public WebElement userManagementLink;

	
	public boolean isOnThisPage() {
		return menuLogoutLink.isDisplayed();
	}
	
	public void logout() {
		menuLogoutLink.click();
		driver.switchTo().alert();
		wait_().until(alertIsPresent()).accept();
	}
	
	public UsersPage gotoUserManagementPage() {
		menuUserManagementLink.click();	
		return MyPageFactory.getPage(driver, UsersPage.class);
	}	
	
	public UsersPage gotoMyProfilePage() {
		menuMyProfileLink.click();	
		return MyPageFactory.getPage(driver, UsersPage.class);
	}		
	
	@Override
	void tryToOpen () {
		MyPageFactory.getPage(driver, LoginPage.class).loginWithValidCredentials("admin", "admin");
	}	
	
	
}
